<template>
  <div class="tjc">
    <div class="head">
      <div class="tit">船舶进出港频次统计</div>
      <div class="opt">
        <el-select v-model="state.pm.type" @change="getData">
          <el-option label="当日" value="everyday" />
          <el-option label="近7日" value="7" />
          <el-option label="近15日" value="15" />
          <el-option label="近30日" value="30" />
        </el-select>
      </div>
    </div>
    <div class="ec" id="tj2"></div>
  </div>
</template>

<script setup>
const state = reactive({
  pm: { type: 'everyday' },
  x:[],
  y1:[],
  y2:[],
  myChart: null,
})
const getData = () => {
  useApi.post("/arhome/dashboard/shipinout", {dimension:state.pm.type}).then((res) => {
    let data = res.data.statdata
    state.x = data.map(x=>x.xaxis)
    state.y1 = data.map(x=>x.inCount)
    state.y2 = data.map(x=>x.outCount)
    chart()
  });
}
const chart = () => {
  let option = {
    backgroundColor: '',
    color: ['#FBBC06', '#00DDFF'],
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross'
      }
    },
    legend: {
      data: ['进港', '出港'],
      right:'5%'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '15%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        data: state.x,
        splitLine: {
          show:true,
          type:'dashed',
          lineStyle: {
            color: "#ffffff22",
          },
        },
      }
    ],
    yAxis: [
      {
        type: 'value',
        splitLine: {
          show:true,
          type:'dashed',
          lineStyle: {
            color: "#ffffff22",
          },
        },
      }
    ],
    series: [
      {
        name: '进港',
        type: 'line',
        data: state.y1
      },
      {
        name: '出港',
        type: 'line',
        data: state.y2
      }
    ]
  };
  state.myChart.setOption(option)
}
onMounted(() => {
  state.myChart = echarts.init(document.getElementById('tj2'), 'dark');
  getData()
})
</script>

<style lang="scss" scoped>
.tjc {
  width: 380px;
  height: 282px;
  background-image: url('/images/bgtj.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  padding: 10px;
}

.head {
  display: flex;
  height: 30px;
  margin-top: 10px;
  border-bottom: 1px solid #5FB1E8;

  .tit {
    margin-left: 90px;
    width: 180px;
    display: flex;
    justify-content: center;
    font-weight: 500;
    font-size: 16px;
    color: #FFFFFF;
    line-height: 22px;
  }

  .opt {
    text-align: right;
  }
}

.ec {
  margin-top: 2px;
  height: 215px;
  .row {
    background: linear-gradient(-148deg, rgba(46, 233, 255, 0.34) 0%, #0F7BC480 100%);
  }
  .row1 {
    height: 35px;
    display: flex;

    .c1 {
      width: 120px;
      display: flex;
      align-items: center;
      padding-left: 30px;
      font-weight: bold;
      font-size: 14px;
      color: #FFAD1E;
    }
    .c2 {
      width: 120px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      font-size: 14px;
      color: #ffffff;
    }
    .c3 {
      width: 120px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      font-size: 14px;
      color: #ffffff;
    }
  }
  .ecc{
    height: 180px;
    overflow-y: hidden;
  }
}


:deep(.el-select) {
  width: 90px;
  margin-top: -4px;
  --el-input-text-color: #ffffff;
  --el-select-input-color: #ffffff;

  .el-select__wrapper {
    background: transparent;
    color: #FFFFFF;
    border: none;
    box-shadow: none;
    border-radius: 0px !important;
  }
}
</style>